/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package questionaire;
import java.util.*;
import com.opensymphony.xwork2.ActionSupport;


/**
 *
 * @author balbir kaur
 */
public class showAction extends ActionSupport{

public HashMap qanda=new HashMap();
public HashMap qandcorrectanswer=new HashMap();
public TreeMap selectedQuestions=new TreeMap();
public TreeMap correctAnswers=new TreeMap();
public int questions=10;

@Override
public String execute(){
QuestionsRead r=new QuestionsRead();
this.setQanda(r.getQuestionAndAnswers());
this.setQandcorrectanswer(r.getQuestionAndCorrectAnswer());
this.setQuestions(r.questionNo);
this.setSelectedQuestions();
this.setCorrectAnswers();
return SUCCESS;
}
public void setQuestions(int questionno){
    this.questions=questionno;

}

public void setCorrectAnswers(){
TreeMap temp=new TreeMap();
Set k=this.selectedQuestions.keySet();
Iterator it=k.iterator();
while(it.hasNext()){
String key=(String)it.next();
temp.put(key, qandcorrectanswer.get(key));
}
this.correctAnswers=temp;
}
public TreeMap getCorrectAnswers(){
return(this.correctAnswers);

}
public TreeMap getSelectedQuestions(){
return this.selectedQuestions;
}
public void setSelectedQuestions(){
    int i=0;
    TreeMap temp=new TreeMap();
        Set<Map.Entry<String,String[]>> set=qanda.entrySet();
        for(Map.Entry<String,String[]>me:set){
        if(i==this.questions){
        break;
        }
        i=i+1;
        temp.put(me.getKey(), me.getValue());
        System.out.println(i);
    }
this.selectedQuestions=temp;
}
public void setQanda(HashMap m){
this.qanda=m;

}
public void setQandcorrectanswer(HashMap n){
    this.qandcorrectanswer=n;


}
public HashMap getQanda(){
    return(this.qanda);
}
public HashMap getQandcorrectanswer(){
    return(this.qanda);
}

public void checkHashValues(){
    Set<Map.Entry<String,String>> set=correctAnswers.entrySet();
    for(Map.Entry<String,String>me:set){
    System.out.println(me.getKey()+":"+me.getValue());
        }
    }
/*public static void main(String args[]){
    showAction sa=new showAction();
    String output=sa.execute();
    sa.checkHashValues();
    System.out.print(output);
    System.out.println(sa.questions);
    
}*/
}
